package hanshunping.easy;

import java.util.ArrayList;
import java.util.Comparator;

public class CollectionsGenneric {
    public static void main(String[] args) {
        ArrayList<Employee> list = new ArrayList<>();
        list.add(new Employee("jack",new Employee().new MyDate(10,99)));
        list.add(new Employee("rose",new Employee().new MyDate(10,97)));
        list.add(new Employee("jams",new Employee().new MyDate(10,98)));
        System.out.println(list+"\n==================================");
        list.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                return o1.getBirthday().getYear()-o2.getBirthday().getYear();
            }
        });
        for(Employee e:list){
            System.out.println(e);
        }
    }
}

class Employee{
    public Employee(){

    }
    private String name;

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", birthday.month=" + birthday.getMonth() +
                ", birthday.year=" + birthday.getYear() +
                '}';
    }

    public Employee(String name, MyDate birthday) {
        this.name = name;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    private MyDate birthday;
    public class MyDate{
        private int month;
        private int year;

        public MyDate(int month, int year) {
            this.month = month;
            this.year = year;
        }

        public int getMonth() {
            return month;
        }

        public void setMonth(int month) {
            this.month = month;
        }

        public int getYear() {
            return year;
        }

        public void setYear(int year) {
            this.year = year;
        }
    }
}